// 服务器端的主程序

#include "Udpserver.hpp"
#include "User.hpp"
#include <iostream>
#include <error.h>
#include <memory>

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "传入错误参数个数。。。。。。。" << std::endl;
        exit(1);
    }

    uint16_t port = std::stoi(argv[1]);

    // 用户管理模块
    std::shared_ptr<UserManger> um = std::make_shared<UserManger>();

    // 网络模块

    std::unique_ptr<UdpServer> server = std::make_unique<UdpServer>(port);


    //将相应的函数实例化
    server->Register_func([&um](InetAddr &id)
                          { um->AddUser(id); },
                          [&um](int sockfd, const std::string &message)
                          { um->Router(sockfd, message);}
                        );

    server->InitServer();

    server->Start();

    return 0;
}